#define  _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<assert.h>

using namespace std;

namespace my_string
{
	class string
	{
	public:
		typedef char* iterator;//定义普通的正向迭代器类型
		typedef const char* const_iterator;//定义const的正向迭代器类型
	
		iterator begin()
		{
			return str_;//返回字符串首地址即可
		}

		iterator end()
		{
			return str_+size_;//返回字符串终止字符的地址即可
		}


		const_iterator begin() const
		{
			return str_;
		}

		
		const_iterator end() const
		{
			return str_+size_;
		}


		string()//无参数的构造函数
		{

		}
		string(const string& str);//拷贝构造函数
		string(const char* s);//使用c字符串构造
		string(size_t n, char c);//使用n个字符c来构造string类

		size_t size() const
		{
			return size_;
		}

		size_t length() const
		{
			return size_;
		}

		size_t capacity() const
		{
			return capacity_;
		}
		void resize(size_t n, char c = '\0');
		void shrink_to_fit();
		void clear();

		char& operator[] (size_t pos);
		const char& operator[] (size_t pos) const;

		string& operator+= (const string& str);
		string & operator+= (const char* s);
		string& operator+= (char c);

		string& append(const string& str);
		string& append(const char* s);
		string& append(size_t n, char c);

		string& insert(size_t pos, const string& str);
		iterator insert(iterator p, char c);
		void push_back(char c);
		iterator erase(iterator p);
		string& erase(size_t pos = 0, size_t len = npos);

		const char* c_str() const
		{
			return this->str_;
		}

		size_t find(const char* str, size_t pos = 0);
		size_t find(const string& s, size_t pos = 0);
		string substr(size_t pos = 0, size_t len = npos);
		void swap(string& s);

		string& operator= (const string& str);
         void swap(string& x, string& y);
		
		~string();

		static const size_t npos = -1;
	private:
		char* str_ = nullptr;//保存字符串的个数,给缺省值
		size_t size_ = 0;
		size_t capacity_ = 0;
	};

	istream& operator>> (istream& is, string& str);
	ostream& operator<< (ostream& os, const string& str);

	string operator+ (const string& lhs, const string& rhs);
	string operator+ (const string & lhs, const char* rhs);
	string operator+ (const char* lhs, const string& rhs);
    string operator+ (const string& lhs, char          rhs);
	string operator+ (char          lhs, const string& rhs);
	
	istream& getline(istream& is, string& str);

	void swap(string& x, string& y);

	void Test_string1();//测试函数
}